﻿using System.Collections.Generic;
using System.ComponentModel;

namespace ComicTool.Model
{

    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private List<DelegateCommand> commands = new List<DelegateCommand>();

        internal void RegisterCommand(DelegateCommand command)
        {
            commands.Add(command);
        }

        internal void RefreshCanExecute()
        {
            commands.ForEach(c => c.UpdateCanExecute());
        }

        protected void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
    }

}
